# Maintainer: Andy Gross <andy.gross@linaro.org>

pkgname=dtc
pkgver=1.4.7
pkgrel=1
pkgdesc="Device Tree Compiler"
arch=('i686' 'x86_64')
url="https://git.kernel.org/pub/scm/utils/dtc/dtc/git"
license=('GPL2')
groups=('base')
makedepends=('python2' 'swig' 'libcrypt-devel')
source=("https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/${pkgname}-${pkgver}.tar.gz"
        01-correct-shared-library-extension.patch)
sha256sums=('603d6f4f5f34921b368e6febe6690c89022d098edda77187a758b8eeeeff53ea'
            '1ed428b3e1f140132522f54984e9b8cc2c20365517569bbd8784852af8dfa503')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  sed -i 's/python\b/python2/' tests/run_tests.sh

  # to make check work
  sed -i 's/__attribute__((weak))//' tests/testutils.c
  sed -i 's|#include <valgrind/|//#include <valgrind/|' tests/testutils.c
  sed -i 's|VALGRIND_|//VALGRIND_|' tests/testutils.c
  patch -p1 -i "${srcdir}/01-correct-shared-library-extension.patch"
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make PREFIX= DESTDIR="${pkgdir}/usr" install

  rm ${pkgdir}/usr/lib/libfdt.dll.1
  rm ${pkgdir}/usr/lib/libfdt-${pkgver}.dll
  mv ${pkgdir}/usr/lib/libfdt.dll ${pkgdir}/usr/bin

  # license
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/README.license ${pkgdir}/usr/share/licenses/${pkgname}/README.license
}

